//
//  SelectViewController.m
//  FloatClouds
//
//  Created by 黄威 on 16/9/6.
//  Copyright © 2016年 黄威. All rights reserved.
//

#import "SelectViewController.h"
#import "CigaretteTypeCell.h"
#import "CigaretteParameterCell.h"
#import "CigarettePriceCell.h"
#import "CigaretteSure.h"


@interface SelectViewController ()<UITextFieldDelegate>
@property (nonatomic, strong) NSArray *arrayOfTobaccoType;
@property (nonatomic, strong) NSArray *arrayOfSectionTitle;
@property (nonatomic, strong) NSArray *arrayOfCellDetail;


@property (nonatomic, copy) NSString *price_max;
@property (nonatomic, copy) NSString *price_min;
@property (nonatomic, copy) NSString *tar_content; //焦油量
@property (nonatomic, copy) NSString *co_content;//一氧化碳量
@property (nonatomic, copy) NSString *nicotine_content;//烟碱量
@property (nonatomic, assign) NSInteger type;// 1烤烟型 2混合型 3外香型 4雪茄型 5雪茄烟


@end

@implementation SelectViewController

- (void)viewDidLoad {
    
    
    
    [self.tableView registerClass:[CigaretteTypeCell class] forCellReuseIdentifier:@"CigaretteTypeCell"];
    [self.tableView registerClass:[CigaretteParameterCell class] forCellReuseIdentifier:@"CigaretteParameterCell"];
    [self.tableView registerClass:[CigarettePriceCell class] forCellReuseIdentifier:@"CigarettePriceCell"];
    [self.tableView registerClass:[CigaretteSure class] forCellReuseIdentifier:@"CigaretteSure"];
    
    [super viewDidLoad];
    [self createNavigation];
    [self handeleData];
   
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(shouhui)
                                                 name:@"shouhui"
                                               object:nil];

    
}

- (void)shouhui{

    [self getData];
    
    
    [self.secdongDelegate changeValueMAX:self.price_max min:self.price_min tar:self.tar_content co:self.co_content nio:self.nicotine_content type:self.type];
    
    
    [self.navigationController popViewControllerAnimated:YES];

}





- (void)createNavigation{
   
    self.navigationItem.title = @"筛选器";
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancel)];
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];
    
}



- (void)cancel{


    [self.navigationController popViewControllerAnimated:YES];

}


- (void)handeleData{

    self.arrayOfTobaccoType = @[@"烤烟型",@"混合型",@"外香型",@"雪茄型",@"雪茄烟"];
    self.arrayOfSectionTitle = @[@"  烟草分类",@"  烟草参数",@"  单盒价格区间",@"  选好了"];

    self.arrayOfCellDetail = @[@"     焦油量",@"     烟气烟碱量",@"     烟气一氧化碳量"];

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return 4;

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    if (section == 0) {
        return 5;
    }if (section == 1) {
        return 3;
    }if (section == 2){
        return 1;
    }if (section == 3){
        return 1;
    }
        
        return 1;
}


- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{


    return self.arrayOfSectionTitle[section];


}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    
    if (indexPath.section == 0) {
        CigaretteTypeCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"CigaretteTypeCell"];
        cell.label.text = self.arrayOfTobaccoType[indexPath.row];
        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
     
        return cell;
        
    }if (indexPath.section == 1) {
        
        CigaretteParameterCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"CigaretteParameterCell"];
        cell.label.text = self.arrayOfCellDetail[indexPath.row];
        cell.tag = indexPath.row + 10000;
        return cell;
     
    }if (indexPath.section == 2) {
        
        CigarettePriceCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"CigarettePriceCell"];
        cell.tag = indexPath.row + 20000;
        return cell;
    }if (indexPath.section == 3) {
        CigaretteSure *cell = [self.tableView dequeueReusableCellWithIdentifier:@"CigaretteSure"];
        return cell;
        
    }
    
    
    
    return nil;

}




- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section == 2) {
        return 120;
    }if (indexPath.section == 3) {
        return 80;
    }

    return 50;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
  
    if (indexPath.section == 0 && indexPath.row != 0) {
        self.type = indexPath.row;
    }
    
    }
   
- (void)getData{

  CigaretteParameterCell *cell1 = [self.tableView viewWithTag:10000];
    self.tar_content = cell1.textfield.text;
  
    
    CigaretteParameterCell *cell2 = (CigaretteParameterCell *)[self.tableView viewWithTag:10001];
    
    self.nicotine_content = cell2.textfield.text;
    
    
    CigaretteParameterCell *cell3 = (CigaretteParameterCell *)[self.tableView viewWithTag:10002];
    self.co_content = cell3.textfield.text;
  
    CigarettePriceCell *cell4 = (CigarettePriceCell *)[self.tableView viewWithTag:20000];
    self.price_min = cell4.textFieldMin.text;
    self.price_max = cell4.textFieldMax.text;
    

}



@end
